/*
 * Copyright 2020-2021 redragon.dongbin
 *
 * This file is part of redragon-erp/赤龙ERP.

 * redragon-erp/赤龙ERP is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.

 * redragon-erp/赤龙ERP is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with redragon-erp/赤龙ERP.  If not, see <https://www.gnu.org/licenses/>.
 */
package com.erp.cux.flexfield.dao.hibernate;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;
import org.redragon.framework.annotation.Cache;
import org.redragon.framework.annotation.Permissions;
import org.redragon.framework.annotation.Permissions.PermissionType;
import org.redragon.framework.annotation.SqlParam;
import org.redragon.framework.hibernate.DaoSupport;
import org.redragon.framework.hibernate.model.Pages;
import org.redragon.framework.util.DaoCRUDUtil;
import com.erp.cux.flexfield.dao.CuxFlexFieldHeadDao;
import com.erp.cux.flexfield.dao.model.CuxFlexFieldHead;
import com.erp.cux.flexfield.dao.model.CuxFlexFieldHeadCO;

@Repository
public class CuxFlexFieldHeadDaoImpl implements CuxFlexFieldHeadDao{ 

    //注入DaoSupport工具类
    @Autowired
    private DaoSupport daoSupport;
    
    @Override
    public void insertDataObject(CuxFlexFieldHead obj) {
        this.daoSupport.insertDataTransaction(obj);
    }

    @Override
    public void updateDataObject(CuxFlexFieldHead obj) {
        this.daoSupport.updateDataTransaction(obj);
    }
    
    @Override
    public void insertOrUpdateDataObject(CuxFlexFieldHead obj) {
        this.daoSupport.insertOrUpdateDataTransaction(obj);
    }

    @Override
    public void deleteDataObject(CuxFlexFieldHead obj) {
        this.daoSupport.deleteDataTransactionJPA(obj);
    }

    @Override
    public List<CuxFlexFieldHead> getDataObjects() {
        return this.daoSupport.getDataAllObject(CuxFlexFieldHead.class);
    }

    @Override
    public CuxFlexFieldHead getDataObject(int id) {
        return (CuxFlexFieldHead)this.daoSupport.getDataObject(CuxFlexFieldHead.class, id);
    }
    
    @Override
    public CuxFlexFieldHead getDataObject(String code) {
        String sql = "select c.* from cux_flex_field_head c where c.ff_head_code = :code";
        
        Map<String, Object> args = new HashMap<String, Object>();
        args.put("code", code);
        
        Map<String, Class<?>> entity = new HashMap<String, Class<?>>();
        entity.put("c", CuxFlexFieldHead.class);
        
        List list = this.daoSupport.selectDataSql(sql, entity, args);
        if(list.size()>0) {
            return (CuxFlexFieldHead)list.get(0);
        }
        
        return null;
    }
    
    @Override
    public List<CuxFlexFieldHead> getDataObjects(CuxFlexFieldHeadCO paramObj) {
        String sql = "select c.* from cux_flex_field_head c where 1=1";
        
        Map<String, Object> args = new HashMap<String, Object>();
        sql = sql + DaoCRUDUtil.getSQLSearch(paramObj, "status", "and c.", args);
        sql = sql + " order by c.ff_head_id desc";
        
        Map<String, Class<?>> entity = new HashMap<String, Class<?>>();
        entity.put("c", CuxFlexFieldHead.class);
        
        return this.daoSupport.selectDataSql(sql, entity, args);
    }
    
    @Override
    public List<CuxFlexFieldHead> getDataObjects(Pages pages) {
        return null;
    }
    
    @Override
    public List<CuxFlexFieldHead> getDataObjects(Pages pages, CuxFlexFieldHeadCO paramObj) {
        String sql = "select c.* from cux_flex_field_head c where 1=1";
        
        Map<String, Object> args = new HashMap<String, Object>();
        sql = sql + DaoCRUDUtil.getSQLSearch(paramObj, "ffHeadCode", "and c.", args);
        sql = sql + DaoCRUDUtil.getSQLSearch(paramObj, "status", "and c.", args);
        sql = sql + " order by c.ff_head_id desc";
        
        this.daoSupport.validateDataObject(paramObj);
        
        Map<String, Class<?>> entity = new HashMap<String, Class<?>>();
        entity.put("c", CuxFlexFieldHead.class);
        
        return this.daoSupport.getDataSqlByPage(sql, entity, args, pages);
    }

    @Override
    public List<Map<String, Object>> getDataObjectsArray(Pages pages, CuxFlexFieldHeadCO paramObj) {
        return null;
    }
    
    @Override
    @Permissions(PermissionType.DATA_AUTH)
    public List<CuxFlexFieldHead> getDataObjectsForDataAuth(@SqlParam String dataAuthSQL, Pages pages, CuxFlexFieldHeadCO paramObj) {
        return null;
    }
    
}
